local skel = fk.CreateSkill {
  name = "rmt__shixiao",
}

local U = require "packages.utility.utility"

skel:addEffect("active", {
  anim_type = "offensive",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  min_target_num = 1,
  max_target_num = 999,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return to_select ~= player and player:canPindian(to_select)
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local targets = effect.tos
    room:setPlayerMark(player, "@@rmt__shixiao-turn", 1)
    local pd = U.jointPindian(player, targets, self.name)
    if pd.winner ~= nil then
      local list = {}
      if pd.fromCard.color == Card.Black then
        table.insert(list, pd.fromCard)
      end
      for _, p in ipairs(targets) do
        if pd.results[p].toCard.color == Card.Black then
          table.insert(list, pd.results[p].toCard)
        end
      end
      if #list > 0 and pd.winner then
        room:moveCardTo(list, Card.PlayerHand, pd.winner, fk.ReasonJustMove, self.name, "", true, pd.winner)
      end
    end
    if pd.winner ~= player and not player.dead then
      local n = player:getHandcardNum()
      for _, p in ipairs(room:getOtherPlayers(player, false)) do
        n = math.min(n, p:getHandcardNum())
      end
      if player:getHandcardNum() > n then
        local throw = room:askToDiscard(player, {
        min_num = player:getHandcardNum() - n,
        max_num = player:getHandcardNum() - n,
        skill_name = skel.name,
        include_equip = false,
        prompt = "#rmt__shixiao-delay",
        cancelable = false,
      })
        local w = 0
        for _, id in ipairs(throw) do
          if Fk:getCardById(id).color == Card.Black then
          w = w + 1
          end
        end
        while w > 0 do
          if player.dead then break end
          room:useVirtualCard("analeptic", nil, player, player, self.name, true)
          w = w - 1
        end
      end
    end
  end,
})

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@@rmt__shixiao-turn") > 0 and data.card.is_damage_card
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@rmt__shixiao-turn", 0)
    data.disresponsiveList = data.disresponsiveList or {}
    for _, p in ipairs(player.room.alive_players) do
      table.insertIfNeed(data.disresponsiveList, p)
    end
  end,
})

Fk:loadTranslationTable{
  ["rmt__shixiao"] = "酾骁",
  [":rmt__shixiao"] = "出牌阶段限一次，你可以令本回合下一张伤害牌无法被响应并与任意名角色拼点，赢家：获得所有黑色拼点牌；若你没赢：调整手牌至场上最少，且视为使用因此失去黑色牌数量的【酒】。",

  ["@@rmt__shixiao-turn"] = "下张伤害牌强中",
  ["#rmt__shixiao-delay"] = "酾骁：您拼点没赢，请弃置手牌至最少，每弃置一张黑色牌便视为使用一张【酒】。",

  ["$rmt__shixiao1"] = "有字不识何须问？径取长弓，奔马丛中射魏鹿！",
  ["$rmt__shixiao2"] = "耀武扬威岂为畏？鼓噪长驱，伏尸枕处彰我名！",
}

return skel
